package com.cbg.service;

import com.cbg.common.PageParam;
import com.cbg.dao.IIpDao;
import com.cbg.pojo.TableIp;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by chenboge on 2016/12/10.
 */
@Service("mService")
public class IpServiceImp implements IIpService {

    @Resource
    private IIpDao mDao;

    @Override
    public List<TableIp> getAll() {
        return mDao.getAll();
    }

    @Override
    public int getItemSize() {
        return mDao.getItemSize() >= 0 ? mDao.getItemSize() : 0;
    }

    @Override
    public PageParam getPageIp(PageParam pageParam) {
        int currPage = pageParam.getCurrPage();
        int pagesize = PageParam.pageSize;
        int offset = pagesize * (currPage-1);
        Map<String, Integer> data = new HashMap<>();
        data.put("pagesize", pagesize);
        data.put("offset", offset);
        List<TableIp> currIps=mDao.getPageIp(data);
        pageParam.setCurrPage(currPage);
        pageParam.setData(currIps);
        return pageParam;
    }
}
